#ifndef CONTAINERCONTROL_H_
#define CONTAINERCONTROL_H_

#include <coecntrl.h>
#include <eiklabel.h>
#include <AknsBasicBackgroundControlContext.h>
#include <aknsdrawutils.h>
#include <aknscontrolcontext.h>
#include <AknsSkinInstance.h>
#include <aknsutils.h>
#include <eiksbfrm.h>
#include <flogger.h>
#include "Image.h"
#include "ScrollBar.h"

enum TScrollDirection
	{
	EVertical,
	EHorizontal
	};
class CContainerControl : public CCoeControl
{
public:
	static CContainerControl* NewL(const TRect& aRect, const CCoeControl* aParent);
	static CContainerControl* NewLC(const TRect& aRect, const CCoeControl* aParent);
	virtual ~CContainerControl();
	TBuf<20> name;
protected:
	CContainerControl();
	void ConstructL(const TRect& aRect, const CCoeControl* aParent);
	
public:
	// from base class CCoeControl
	TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
	void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	
public: // own methods
    // NOTE: Transfer ownership to CContainerControl
    void AddControlL(CCoeControl* aControl);
    void RemoveItem(CCoeControl* aControl);
    void RemoveAllItems();
    TInt Count();
    CCoeControl* getControl(TInt aIndex);
    CCoeControl* getFocusControl();
    void setFocusControl(TInt aIndex);
    TInt getFocusIndex() const;
    virtual void UpdateControls(TInt aOffset = 0, TBool aChangeCurPos = ETrue);
    void AdjustPosition();
    void setEnableSkin(TBool aEnable);
    void SetBackGroundBitmapL(CImage* aImage);
    void setDrawBgType(TInt aType);
    void setScrollDirection(TInt aDirection);
    TBool CanScroll();
    
protected:
	TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
	// from CCoeControl
    void Draw(const TRect& aRect) const;
    virtual void SizeChanged();
    virtual void HandleResourceChange(TInt aType);
    
protected:
    void MoveFocusUpL();
    void MoveFocusDownL();
    void MoveFocusLeftL();
    void MoveFocusRightL();
    void UpdateScrollBarFrameL();
    TBool IsInRect(CCoeControl* aCtrl);
    void ShowScrollBar();
    void HideScrollBar();
    TBool IsInRect(TPoint aPt1, TPoint aPt2, TInt aSize = 10);
    
protected:
    TInt 								iTotalHeight;
    TInt 								iCurPos;
    TInt 								iScrollDirection;

    CAknsBasicBackgroundControlContext*	iBgContext;
    CScrollBar*							iScrollBar;
    CCoeControl* 						iFocusControl;
    TInt 								iMaxControlIndex;
    TBool                               iEnableSkin;
    CImage*                             iBackGroundBitmap;
    TInt 								iDrawBgType;
	CCoeControl* 						iFirstControl;
	TInt 								iFirstPositionX;
	TInt 								iFirstPositionY;
    TPoint 								iDownClickPt;
    TBool 								iHasClicked;
};

#endif /*CONTAINERCONTROL_H_*/
